﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace InHD.utilities
{
    public static class ValidatingUtilities
    {
        public static bool ValidateEmail(string email)
        {
            string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";

            return !Regex.IsMatch(email, pattern, RegexOptions.IgnoreCase);
        }

        public static bool ValidatePhone(string phone)
        {
            return ValidateNumber(phone);
        }

        public static bool ValidateUsername(string username)
        {
            // a-z, 0-9, underscore, hyphen, length from 5 characters
            string pattern = @"^[a-z0-9_-]{5,}$";

            return !Regex.IsMatch(username, pattern, RegexOptions.IgnoreCase);
        }

        public static bool ValidateNumber(string number)
        {
            string pattern = @"^\d+$";

            return !Regex.IsMatch(number, pattern, RegexOptions.IgnoreCase);
        }

        public static bool ValidateMissing(string value)
        {
            return String.IsNullOrEmpty(value) || value.Trim() == String.Empty;
        }
    }
}
